import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/Index.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/Home/index.vue'),
        redirect: '/home',
        children: [
          {
            path: '',
            name: 'Home',
            component: () => import('../views/Home/home.vue'),
          },
          {
            path: 'img',
            name: 'img',
            component: () => import('../views/Home/img.vue'),
          },
          {
            path: 'shopList',
            name: 'ShopList',
            component: () => import('../views/Home/shopList.vue'),
          },
        ]
      },
      {
        path: '/shop',
        name: 'shop',
        component: () => import('../views/Shop/index.vue'),
        redirect: '/shop/shopList',
        children: [
          {
            path: 'shopList',
            name: 'shopList',
            component: () => import('../views/Shop/shopList.vue'),
          },
          {
            path: 'classList',
            name: 'classList',
            component: () => import('../views/Shop/classList.vue'),
          },
          {
            path: 'shopSpec',
            name: 'shopSpec',
            component: () => import('../views/Shop/shopSpec.vue'),
          },
          {
            path: 'shopType',
            name: 'shopType',
            component: () => import('../views/Shop/shopType.vue'),
          },
          {
            path: 'shopComment',
            name: 'shopComment',
            component: () => import('../views/Shop/shopComment.vue'),
          },
        ]
      },
      {
        path: '/order',
        name: 'order',
        component: () => import('../views/Order/index.vue'),
        redirect: '/order',
        children: [
          {
            path: '',
            name: 'Order',
            component: () => import('../views/Order/order.vue'),
          },
          {
            path: 'bill',
            name: 'bill',
            component: () => import('../views/Order/bill.vue'),
          },
          {
            path: 'service',
            name: 'service',
            component: () => import('../views/Order/service.vue'),
          },
        ]
      },
      {
        path: '/vip',
        name: 'vip',
        component: () => import('../views/Vip/index.vue'),
        redirect: '/vip/vipList',
        children: [
          {
            path: 'vipList',
            name: 'vipList',
            component: () => import('../views/Vip/vipList.vue'),
          },
          {
            path: 'vipGrade',
            name: 'vipGrade',
            component: () => import('../views/Vip/vipGrade.vue'),
          },
        ]
      },
      {
        path: '/set',
        name: 'set',
        component: () => import('../views/Set/index.vue'),
        redirect: '/set',
        children: [
          {
            path: '',
            name: 'Set',
            component: () => import('../views/Set/set.vue'),
          },
          {
            path: 'logistics',
            name: 'logistics',
            component: () => import('../views/Set/logistics.vue'),
          },
          {
            path: 'admin',
            name: 'admin',
            component: () => import('../views/Set/admin.vue'),
          },
          {
            path: 'money',
            name: 'money',
            component: () => import('../views/Set/money.vue'),
          },
        ]
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, form, next) => {
  if (localStorage.getItem('token')) {
    var date = new Date().getTime()
    if (date < localStorage.getItem('time')) {
      next()
    } else {
      if (to.path == '/login') {
        next()
      } else {
        next('/login')
      }
    }
  } else {
    if (to.path == '/login') {
      next()
    } else {
      next('/login')
    }
  }
})

export default router
